<?xml version="1.0" encoding="utf-8" ?>
[#include "/WEB-INF/pages/common/taglibs.ftl"]
[#macro _script]
	<script type="text/javascript" src="[@c.url value='/js/plugins/jquery.form.js'/]"></script>
	<script type="text/javascript">
		var base = (function(){
			// 事件绑定
			function _addEventListeners() {
				// 维护
				$('a[act=edit]').unbind('click').click(function(){
					var id = $(this).parent().attr('tval');
					[@c.url var="editUrl" value='/manage/Article_edit.action' scope="page"]
						[@c.param name="categoryId" value="${categoryId}"/]
					[/@c.url]
					var url = "${editUrl}&id=" + id;
					//$.get(url, {'id':id, 'ajax':'true'}, function(data) {
					//	$('#body').html(data);
					//})
					window.location = url;
				})
				
				// 删除
				$('a[act=delete]').unbind('click').click(function(){
					var id = $(this).parent().attr('tval');
					$( "#delete-confirm" ).dialog({
						resizable: false,
						height:160,
						width:260,
						modal: true,
						buttons: {
							"删除": function() {
								[@c.url var="backUrl" value='/manage/Article_list.action' scope="page"]
									[@c.param name="categoryId" value="${categoryId}"/]
									[@c.param name="channelId" value="${channelId}"/]
									[@c.param name="currentPage" value="${currentPage}"/]
								[/@c.url]
								window.location = "[@c.url value='/manage/Article_delete.action?id='/]" + id + "&backurl=${backUrl}";
								$( this ).dialog( "close" );
							},
							"取消": function() {
								$( this ).dialog( "close" );
							}
						}
					});
					$( "#delete:ui-dialog" ).dialog( "destroy" );
					return false;
				})
				
				// Create jqxExpander
        		$('.jqxExpander').each(function(i){
        			var height = $(this).css('height');
        			if (height == null) {
        				height = '500px';
        			}
        			$(this).jqxExpander({showArrow: false, toggleMode: 'none', height: height, theme: base.config.theme });
        		})
        		
        		// 必须先渲染控件,后绑定事件
				//频道切换的select切换事件
				$('#channelSelect').change(function() {
					$('form[name=channelForm]').attr('action', "[@c.url value='/manage/Article_list.action'][/@c.url]");
					$('form[name=channelForm]').submit();
				})
				
				$('#articleSearch').unbind().submit(function(){
					var params = {'ajax':'true', 'piece':'true'};
					var url = $(this).attr('action');
					var paraArray = $(this).serializeArray();
					var index = 0;
					jQuery.each(paraArray, function(i, e) {
						if (e.value != ""){
							params[e.name] = e.value;
						}
					});
					$.get(url, params, function(result){
						$('#articleList').html(result);
						_addEventListeners();
					})
					return false;
				})
			}
			
			// 页面渲染
			function _treeRender () {
				// Create jqxTree
        		$('#jqxTree').jqxTree({height:'448px;', theme: base.config.theme });
        		$('#jqxTree').unbind().bind('select', function (event) {
	                var args = event.args.element.outerHTML;
	                var id = $('a', $(args)).attr('ckey');
					//使用一个ajax请求,去渲染body部分
					//参数注意：ajax代表是一个ajax请求;渲染本页的body,但在装饰器中为一个div体
					//所以在装饰器页里,将内容页放入不同位置,但内容页的ajax不会改变.
	                $.get(base.config.url, {'categoryId':id, 'ajax':true, 'piece':true}, function(data){
	                	$('#articleList').html(data);
	                	_addEventListeners();
	                })
	            });
			};
			return {
                config: {
                	url : null,
                    theme: null
                },
                init: function () {
                	_addEventListeners();
                	_treeRender();
                }
			}
		}());
		
		$(function(){
			var link = "[@c.url value='/manage/Article_list.action?channelId=${channelId}&currentPage=${currentPage}' /]";
			base.config.theme = getTheme();
			base.config.url = link;
            //Initializing the form
			base.init();
		})
	</script>
[/#macro]
[#if piece==true]
	[@_script /]
	<!--设置提交行为-->
	[#assign act="save" /]
	<!--设置table渲染到指定ID节点-->
	[#assign renderTo="#articleList"]
	[#include "/WEB-INF/pages/manage/_articleList.ftl"]
[#else]
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Insert title here</title>
		<meta name="menu" content="AdminMenu"/>
		<meta name="heading" content="heading"/>
		<style type="text/css">
			.article {
				padding:0;
				margain:0;
			}
			.category_tree {
				width:240px;
				float:left;
				margin-left:2px;
			}
			.article_search {
				margin-left:252px;
			}
			.article_list {
				margin-top:-2px;
			}
		</style>
		[@_script /]
	</head>
	<body id="body" class="art_content">
		<div class="article">
			<div class="category_tree">
		    	[@s.action name="Category_tree" executeResult="true" namespace="/manage"]
		    		[@s.param name="ajax" value="true" /]
					[@s.param name="channelId" value="channelId" /]
		    	[/@s.action]
		    </div>
		
			<div class="article_search">
				<div class="jqxWidget">
					<div class="jqxExpander" style="height:60px;">
						<div>检索</div>	
						<div>
							<form id="articleSearch" action="[@c.url value='/manage/Article_list.action?channelId=${channelId}&currentPage=${currentPage}' /]" method="post">
								<table>
									<tr>
										<td><select name="article.comment" style="width:90px;">
											<option value="">评论状态</option>
											<option value="true" [#if (article.isComment())?? && article.isComment()==true]selected="selected"[/#if] >允许评论</option>
											<option value="false" [#if (article.isComment())?? && article.isComment()==false]selected="selected"[/#if] >禁止评论</option>
										</select></td>
										<td>
											<select name="article.draft" style="width:90px;">
												<option value="">发布状态</option>
												<option value="true" [#if (article.isDraft())?? && article.isDraft()==true]selected="selected"[/#if] >草稿</option>
												<option value="false" [#if (article.isDraft())?? && article.isDraft()==false]selected="selected"[/#if] >发布</option>
											</select>
										</td>
										<td>
											<select name="article.check" style="width:90px;">
												<option value="">审核状态</option>
												<option value="true" [#if (article.isCheck())?? && article.isCheck()==true]selected="selected"[/#if] >审核</option>
												<option value="false" [#if (article.isCheck())?? && article.isCheck()==false]selected="selected"[/#if] >开放</option>
											</select>
										</td>
										<td>
											<select name="article.permission" style="width:90px;">
												<option value="">许可状态</option>
												<option value="true" [#if (article.isPermission())?? && article.isPermission()==true]selected="selected"[/#if] >需要认证</option>
												<option value="false" [#if (article.isPermission())?? && article.isPermission()==false]selected="selected"[/#if] >开放访问</option>
											</select>
										</td>
										<td>&nbsp;文章标题:<input name="article.title" type="text" value=""/> 禁用<input name="article.enabled" type="checkbox" [#if (article.isEnabled())?? && article.isEnabled()==false]checked="checked"[/#if] value="false"/></td>
										<td><input type="submit" value="查询" /></td>
									</tr>
								</table>
							</form>
						</div>
					</div>
				</div>
				<div id="articleList" class="article_list">
					<!--设置提交行为-->
					[#assign act="save" /]
					<!--设置table渲染到指定ID节点-->
					[#assign renderTo="#articleList"]
					[#include "/WEB-INF/pages/manage/_articleList.ftl"]
				</div>
			<div>
			<div style="clear: both;"></div>
		</div>
	</body>
	</html>
[/#if]